<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>借款列表</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/css/base.css" rel="stylesheet"
	type="text/css" />
<link href="/resources/js/miniui/themes/default/miniui.css"
	rel="stylesheet" type="text/css" />
<script src="/resources/js/jquery-1.6.2.min.js"
	type="text/javascript"></script>
<script src="/resources/js/miniui/miniui.js"
	type="text/javascript"></script>
<script src="/resources/js/ckeditor/ckeditor.js"
	type="text/javascript"></script>
<script src="/resources/js/statusUtil.js" type="text/javascript"></script>
<script src="/resources/js/wbkDate.js" type="text/javascript"></script>
<style type="text/css">
.errorText {
	color: red;
}
.td1 {
	width: 20%;
	text-align: right;
}

.td2 {
	width: 30%;
	text-align: left;
}

.td3 {
	width: 12%;
	text-align: right;
}

.td4 {
	width: 38%;
	text-align: left;
}
</style>
</head>
<body>
	<h1>借款列表</h1>
	<div style="padding-top: 5px; padding-bottom: 5px; width: 95%;">
		<a class="mini-button"
				img="/resources/js/miniui/themes/icons/edit.gif"
				onclick="editRow()">审核</a>
	</div>
	<div style="padding-top: 5px; padding-bottom: 5px; width: 95%;">
		<span>用户手机号：</span><input type="text" id="search_phone" />
		<span>状态：</span><input id="search_status" class="mini-combobox" valueField="data" textField="data"
						valueFromSelect="true" url="/borrow/getStatusJson" />
		<input type="button" value="查找" onclick="search()" />
	</div>
	<div id="mini-datagrid" class="mini-datagrid"
		style="width: 95%; height: 400px;"
		url="/borrow/selectByPage" pageSize="20" idField="id"
		allowResize="true">

		<div property="columns">
			<div type="indexcolumn">序号</div>
			<div type="checkcolumn">选择</div>
			<div field="userId">用户ID</div>
			<div field="realname">用户姓名</div>
			<div field="phone">手机号</div>
			<div field="money">借款金额（元）</div>
			<div field="deadline">期限（月）</div>
			<div field="repayType">还款方式</div>
			<div field="status">状态</div>
			<div field="createTime" renderer="tipTimeRen">发布时间</div>
		</div>
	</div>
	
	<!-- 修改状态 -->
	<div id="editWindow" class="mini-window" title="修改状态"
		style="width: 400px;" showModal="true" allowResize="true"
		allowDrag="true">
		<div id="editform" class="form">
			<input class="mini-hidden" name="id" value="0" />
			<input class="mini-hidden" name="userId" value="0" />
			<table style="width: 100%; text-align: center;">
				<tr>
					<td style="width: 30%; text-align: right;">借款金额(元)：</td>
					<td style="width: 40%; text-align: left;"><input name="money"
						class="mini-textbox" /></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right">期限(月)：</td>
					<td style="width: 40%; text-align: left;">
						<input name="deadline" class="mini-textbox" />
					</td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right;">还款方式：</td>
					<td style="width: 40%; text-align: left;"><input name="repayType"
						class="mini-textbox" /></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right;">状态：</td>
					<td style="width: 40%; text-align: left;"><input name="status"
						class="mini-combobox" valueField="data" textField="data"
						valueFromSelect="true" url="/borrow/getStatusJson"/></td>
				</tr>
				<tr>
					<td
						style="text-align: center; padding-top: 5px; padding-right: 20px;"
						colspan="3"><a class="mini-button"
						img="/resources/js/miniui/themes/icons/save.gif"
						onclick="saveRow()">保存</a> <a class="mini-button"
						img="/resources/js/miniui/themes/icons/cancel.gif"
						onclick="cancelRow()">取消</a></td>
				</tr>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
	mini.parse();
	var datagrid = mini.get("mini-datagrid");
	var editWindow = mini.get("editWindow");
	datagrid.load();
	
	var form = new mini.Form("editform");
	CKEDITOR.replace('content');
	
	function search(){
		datagrid.load({phone : $('#search_phone').val(),
				status : mini.get("#search_status").getValue()});
	}

	function editRow() {
		var node = datagrid.getSelected();
		if (node) {
			editWindow.show();
			form.clear();
			form.setData(node);
		} else {
			mini.alert("请选择一条!");
		}
	}
	
	function saveRow() {
		var json = form.getData();
		if (json.id == 'undefined' || json.id == '') {
			json.id = 0;
		}
		$.ajax({
			url : "/borrow/update",
			data : json,
			type : "post",
			success : function(text) {
				editWindow.hide();
				datagrid.reload();
				mini.alert("操作成功!");
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});

	}
</script>

</html>
